<div class="g12 nodrop" style="margin-bottom: 43px;">

    <h1> <? if (isset($mediadata)) {echo 'Ažuriranje medije'; } else echo 'Nova medija' ?> </h1>

     <p style="line-height: 13px;">

        <? 
        
            switch($_GET['type']){
            
            case 'img': echo 'Fotografija'; break;
            case 'yt': echo 'YouToube video'; break;
            
        }     
         ?>

    </p>

    <? if (isset($mediadata)==false){ ?>
    
    <ul class="breadcrumb" data-connect="breadcrumbcontent">

        <li><a href="<?=$url?>media/newform?type=img"><span>Fotografija</span></a></li>
        <li><a class="active" href="javascript:"><span>YouTube Video</span></a></li>

    </ul>
    
    <?}?>

    <!--FORM YOUTUBE VIDEO-->    
    <div style="width: 100%;">

        <div id="srvrserror-3"></div>

        <button id="dialog_confirm" style="display: none;">Confirm Dialog (confirm)</button>

        <form id="frm_yt" action="javascript:" method="post" autocomplete="off" data-confirm-send="false">

            <fieldset>

                <section><label for="input">Naziv</label>
                    <div><input type="text" id="name" name="name-yt" required value="<? if (isset($mediadata)) echo $mediadata[0]['name']; ?>"></div>
                </section>

                <section><label for="input">Opis - (Interni text za laksu identifikaciju)</label>
                    <div><input type="text" id="description" name="description" required value="<? if (isset($mediadata)) echo $mediadata[0]['description']; ?>"></div>
                </section>

                <section><label for="input">Autor</label>
                    <div><input type="text" id="author" name="author" required value="<? if (isset($mediadata)) echo $mediadata[0]['author']; ?>"></div>
                </section>

                <section><label for="input">Direktorijum</label>
                    <div>
                        <select name="directory" id="directory" style="color: #555555; line-height: 16px; padding: 3px 0 0 3px; width: 17em;">
                            <option value="0">-- Molim odaberite</option> 
                            <?
                                foreach($directoryMedia as $directory){

                                ?><option value="<?=$directory['id'];?>" <? if(isset($mediadata)){if(($mediadata[0]['directory_id']==$directory['id'])){ echo 'selected=selected';}} ?>><?=$directory['name'];?></option><?

                                }
                            ?>
                        </select>
                    </div>
                </section>

                <section><label for="input">Link za video fajl</label>
                    <div>
                        <table style="background: none;">
                            <tr>
                                <td style="text-align: left; vertical-align: top;">
                                    <div><input type="text" id="filename" name="filename" required value="<? if (isset($mediadata)) echo $mediadata[0]['file']; ?>"></div>   
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <div id="displayImage" >
                                    <? if (isset($mediadata)) { ?>
                                    

                                        <iframe width="420" height="315" src="http://www.youtube.com/embed/<?=$mediadata[0]['file']?>" frameborder="0" allowfullscreen></iframe>

                                    
                                    <?}else {?>
                                         <a href="javascript:" id='embed_video'>Provjeri link</a>
                                         <script type="text/javascript">
                                          $('#embed_video').live('click', function(){
                                             
                                             var file = $('#filename').val();
                                             
                                             if(file == ''){
                                                 alert("Molio unesite link.");
                                                 return;
                                             }
                                             
                                             $('#displayImage').html('<iframe width="420" height="315" src="http://www.youtube.com/embed/'+file+'" frameborder="0" allowfullscreen></iframe>');
                                              
                                          })
                                         </script>
                                    <?}?>
                                    </div> 
                                </td>
                            </tr>
                        </table>
                    </div>
                </section>

                <section><label for="input">Tagovi</label>
                    <div><input type="text" id="tags" name="tags" required value="<? if (isset($mediadata)) echo $mediadata[0]['tags']; ?>"></div>
                </section>

                <!--<input type="hidden" name="filename" id="filename" value="" /> -->
                <input type="hidden" name="type" id="type" value="img" />

                <section>
                    <button class="submit small" onclick="return false;"><? if (isset($mediadata[0]['name'])) {echo 'Ažuriraj Mediju'; }else echo 'Kreiraj mediju'; ?></button>
                </section> 

            </fieldset>

        </form>

    </div>

</div>

<!-- VARIABLES TO edit_new.js -->
<script type="text/javascript">
    var appmode;
    var get_id;
    <?  if (isset($_GET['id'])){ ?> 
        appmode = 'edit';
        get_id = '<?=$_GET['id']?>';

        <?}else{?> 
        appmode = 'insert'; 
        get_id = -1;
        <? } ?>
</script>
<style>
    #uniform-directory span{
        width: 17em;
    }
</style>